SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_GetTabsByPackageID]
	@PortalID INT,
	@PackageID INT,
	@ForHost BIT
AS

IF (@ForHost = 1)
	-- Get all host pages and portal pages
	SELECT DISTINCT T.*
	FROM dbo.DnnProduct_vw_Modules M 
		INNER JOIN dbo.DnnProduct_DesktopModules DM 
			ON M.DesktopModuleID=DM.DesktopModuleID
		INNER JOIN dbo.DnnProduct_vw_Tabs T 
			ON T.TabID=M.TabID
	WHERE DM.PackageID=@PackageID
		AND T.IsDeleted=0
		AND M.IsDeleted=0
	ORDER BY T.PortalID, T.TabName
ELSE
	-- Get pages for a specific portal (or host pages only)
	SELECT DISTINCT T.*
	FROM dbo.DnnProduct_vw_Modules M 
		INNER JOIN dbo.DnnProduct_DesktopModules DM 
			ON M.DesktopModuleID=DM.DesktopModuleID
		INNER JOIN dbo.DnnProduct_vw_Tabs T 
			ON T.TabID=M.TabID
	WHERE DM.PackageID=@PackageID
		AND ((@PortalID IS NULL AND T.PortalID IS NULL) OR T.PortalID = @PortalID)
		AND T.IsDeleted=0
		AND M.IsDeleted=0
	ORDER BY T.TabName
GO
